package com.hazardSoft.eStore.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hazardSoft.eStore.common.exception.SystemException;
import com.hazardSoft.eStore.entities.Category;
import com.hazardSoft.eStore.entities.City;
import com.hazardSoft.eStore.entities.Department;
import com.hazardSoft.eStore.entities.OfferType;
import com.hazardSoft.eStore.entities.Role;
import com.hazardSoft.eStore.integration.ListDelegate;

/**
 * Servlet implementation class ListTest
 */
public class ListTest extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListTest() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doAll(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doAll(request, response);
	}
	
	private void doAll(HttpServletRequest request, HttpServletResponse response) {
		
		ListDelegate listDelegate;
		
		List<Category> categoryList;
		List<Department> departmentList;
		List<City> cityList;
		List<City> citiesByDepartmentList;
		List<OfferType> offerTypeList;
		List<Role> roleList;
		
		try 
		{
			listDelegate = new ListDelegate();
			
			categoryList = listDelegate.listCategories();
			for (Category category : categoryList) 
			{
				System.out.println(category.getName());
			}
			
			System.out.println("////////////////////");
			
			departmentList = listDelegate.listDepartments();
			for (Department department : departmentList) 
			{
				System.out.println(department.getName());
			}
			
			System.out.println("////////////////////");
			
			cityList = listDelegate.listCities();
			for (City city : cityList) 
			{
				System.out.println(city.getName());
			}
			
			System.out.println("////////////////////");
			
			citiesByDepartmentList = listDelegate.listCitiesByDepartment(new Department(2));
			for (City city : citiesByDepartmentList) 
			{
				System.out.println(city.getName());
			}
			
			System.out.println("////////////////////");
			
			offerTypeList = listDelegate.listOfferTypes();
			for (OfferType offerType : offerTypeList) 
			{
				System.out.println(offerType.getName());
			}
			
			System.out.println("////////////////////");
			
			roleList = listDelegate.listRoles();
			for (Role role : roleList) 
			{
				System.out.println(role.getName());
			}
			
		}
		catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
